package br.com.rhinovet.comparator;

import java.util.Comparator;
import java.util.Date;

import br.com.rhinovet.bean.HistoricoBean;

public class DataProcedimentoComparator implements Comparator<HistoricoBean> {
    public int compare(HistoricoBean historico1, HistoricoBean historico2) {
    	return comparaDataDecrescente(
    			historico1 != null ? historico1.getDataProcedimento() : null,
    			historico2 != null ? historico2.getDataProcedimento() : null);
	}
    
    public static int comparaDataDecrescente(Date data1, Date data2) {
    	if (data1 == null && data2 != null) {
    		return 1;
    	} else if (data1 == null && data2 == null){
    		return 0;
    	} else if (data1 != null && data2 == null){
    		return -1;
    	} else {
    		return data2.compareTo(data1);
    	}
	}
}
